import request from '@/utils/request'

const baseURL = process.env.VUE_APP_BASE_API
const uploadURL = '/common/upload'

// 通用上传地址
export const uploadAddress = baseURL + uploadURL

// 通用上传方法
export function upload(data) {
  const formData = new FormData()
  formData.append('file', data)
  return request({
    url: uploadURL,
    method: 'post',
    data: formData
  })
}

// 通用下载方法
export function download(fileName) {
  window.location.href = baseURL + '/common/download?fileName=' + encodeURI(fileName) + '&delete=' + true
}

// oss直传policy获取接口
export function getOssPolicy() {
  return request({
    url: '/common/upload/policy',
    method: 'get'
  })
}
